package com.cn.jx.manager.dao;

import java.util.Date;

import org.springframework.data.jpa.repository.JpaRepository;
import org.springframework.data.jpa.repository.JpaSpecificationExecutor;
import org.springframework.data.jpa.repository.Modifying;
import org.springframework.data.jpa.repository.Query;
import org.springframework.data.repository.query.Param;

import com.cn.jx.manager.po.MessageUser;

/**
 * 
 * @author 姜旭
 * @version v1.11.20.2019
 * @since 
 * <p>创建时间：2019年12月23日
 * <p>功能描述：
 * <p>官方网站：management/admin/index
 * <p>邮箱地址：524577360@qq.com
 */
public interface MessageUserRepository extends JpaRepository<MessageUser,String>,JpaSpecificationExecutor<MessageUser>{
	/*所有收件箱未读*/
	@Query("select count(1) from MessageUser  where userId=:userId and receivMethod='receive' and delFlg=0 and receivStatus=0 ")
	public int findAllInboxUnReadCount(@Param(value = "userId") String userId);
	
	/*所有收件箱*/
	@Query("select count(1) from MessageUser  where userId=:userId and receivMethod='receive' and delFlg=0 ")
	public int findAllInboxCount(@Param(value = "userId") String userId);
	
	/*已发送*/
	@Query("select count(1) from MessageUser  where userId=:userId and receivMethod='send' and delFlg=0 and receivStatus=1 ")
	public int findAllOutboxSendCount(@Param(value = "userId") String userId);
	
	/*草稿箱 未发送*/
	@Query("select count(1) from MessageUser  where userId=:userId and receivMethod='send' and delFlg=0 and receivStatus=0  ")
	public int findAllOutboxUnSendCount(@Param(value = "userId") String userId);
	
	/*已删除*/
	@Query("select count(1) from MessageUser  where userId=:userId  and delFlg=1 ")
	public int findAllDeleteCount(@Param(value = "userId") String userId);
	
	
	@Modifying
	@Query("update MessageUser set receivStatus=1,operatTime=:otime where id =:id and receivMethod='receive' ")
	public void updateInboxRead(@Param(value = "id") String id,@Param(value = "otime") Date otime);
	
}
